const Service = require('egg').Service;
class ChatService extends Service {
    // 界面列表
    async list() {
        const options = {
            limit: 100,
            attributes: ['id', 'number', 'name', 'msg'],
            order: [['created_at', 'DESC']]
        };
        return await this.ctx.model.Chat.findAndCountAll(options);
    }

    // 添加聊天信息
    async new(data) {
        return await this.ctx.model.Chat.create(data);
    }

    // 清空聊天记录
    async clear() {     
        return await this.ctx.model.Chat.destroy({
            where: {
                id: {
                    ne: null
                }
            }
        });
    }
}
module.exports = ChatService;